<?php echo $header; ?>
<style>.list tbody td{background:none;}</style>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/customer.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a href="<?php echo $insert; ?>" class="button"><?php echo $button_insert; ?></a></div>
    </div>
    <div class="content">
	 <div class="pagination"><?php echo $pagination; ?></div>
      <form action="" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
				<td></td>
               <td class="left"><?php if ($sort == 'c.madn') { ?>
                <a href="<?php echo $sort_madn; ?>" class="<?php echo strtolower($order); ?>">Mã Đăng Nhập</a>
                <?php } else { ?>
                <a href="<?php echo $sort_madn; ?>">Mã Đăng Nhập</a>
                <?php } ?></td> <td class="left">Mã Giới Thiệu</td>
				<td class="left"><?php if ($sort == 'c.level1') { ?>
                <a href="<?php echo $sort_level; ?>" class="<?php echo strtolower($order); ?>">Cấp</a>
                <?php } else { ?>
                <a href="<?php echo $sort_level; ?>">Cấp</a>
                <?php } ?></td>
				<td class="left">Lần 1</td>
				<td class="left">Lần 2</td>
				<td class="left"><?php if ($sort == 'ci.name') { ?>
                <a href="<?php echo $sort_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_name; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_name; ?>"><?php echo $column_name; ?></a>
                <?php } ?></td>
              <td class="left"><?php if ($sort == 'ci.email') { ?>
                <a href="<?php echo $sort_email; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_email; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_email; ?>"><?php echo $column_email; ?></a>
                <?php } ?></td>
              <td class="left"><?php if ($sort == 'c.status') { ?>
                <a href="<?php echo $sort_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_status; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_status; ?>"><?php echo $column_status; ?></a>
                <?php } ?></td>
              <td class="left"><?php if ($sort == 'c.date_added') { ?>
                <a href="<?php echo $sort_date_added; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_date_added; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_date_added; ?>"><?php echo $column_date_added; ?></a>
                <?php } ?></td>
              <!--<td class="left"><?php echo $column_login; ?></td>-->
              <td class="right"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td></td>
              <td><input type="text" style="width:75px" name="filter_madn" value="<?php echo $filter_madn; ?>" /></td>
              <td><input type="text" style="width:75px" name="filter_parent" value="<?php echo $filter_parent; ?>" /></td>
              <td><input type="text" style="width:50px" name="filter_level" value="<?php echo $filter_level; ?>" /></td>
              <td></td>
              <td></td>
			  <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" /></td>
              <td><input type="text" name="filter_email" value="<?php echo $filter_email; ?>" /></td>
              <td><select name="filter_status">
                  <option value="*"></option>
                  <?php if ($filter_status) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <?php } ?>
                  <?php if (!is_null($filter_status) && !$filter_status) { ?>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
              <td><input type="text" name="filter_date_added" value="<?php echo $filter_date_added; ?>" size="12" id="date" /></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $button_filter; ?></a></td>
            </tr>
            <?php if ($customers) { ?>
			<?php $index = Count($customers);?>
            <?php foreach ($customers as $customer) { ?>
			<?php if($customer['level']){?>
				<tr style="background:<?php echo $customer['color_level'];?>">
			<?php } elseif(!$customer['status_id']) {?>
				<tr style="background:#d3d3d3">
			<?php } else { ?>
				<tr>
			<?php }?>
              <td class="left"><?php echo $index; ?></td>
              <td class="left"><?php echo $customer['madn']; ?></td>
              <td class="left"><?php echo $customer['parent']; ?></td>
              <td class="left"><?php echo $customer['level']; ?></td>
              <td class="left"><?php echo $customer['price']; ?></td>
              <td class="left"><?php echo $customer['price2']; ?></td>
              <td class="left"><?php echo $customer['name']; ?></td>
              <td class="left"><?php echo $customer['email']; ?></td>
              <td class="left"><?php echo $customer['status']; ?></td>
              <td class="left"><?php echo $customer['date_added']; ?></td>
              <!--<td class="left"><select onchange="((this.value !== '') ? window.open('index.php?route=sale/customer/login&token=<?php echo $token; ?>&customer_id=<?php echo $customer['customer_id']; ?>&store_id=' + this.value) : null); this.value = '';">
                  <option value=""><?php echo $text_select; ?></option>
                  <option value="0"><?php echo $text_default; ?></option>
                  <?php foreach ($stores as $store) { ?>
                  <option value="<?php echo $store['store_id']; ?>"><?php echo $store['name']; ?></option>
                  <?php } ?>
                </select></td>-->
              <td class="right"><?php foreach ($customer['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
			<?php $index--;?>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="11"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
     
    </div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=sale/customer&token=<?php echo $token; ?>';
	
	var filter_madn = $('input[name=\'filter_madn\']').attr('value');
	
	if (filter_madn) {
		url += '&filter_madn=' + encodeURIComponent(filter_madn);
	}
	
	var filter_parent = $('input[name=\'filter_parent\']').attr('value');
	
	if (filter_parent) {
		url += '&filter_parent=' + encodeURIComponent(filter_parent);
	}
	
	var filter_level = $('input[name=\'filter_level\']').attr('value');
	
	if (filter_level) {
		url += '&filter_level=' + encodeURIComponent(filter_level);
	}
	
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
	
	var filter_email = $('input[name=\'filter_email\']').attr('value');
	
	if (filter_email) {
		url += '&filter_email=' + encodeURIComponent(filter_email);
	}
	
	var filter_status = $('select[name=\'filter_status\']').attr('value');
	
	if (filter_status != '*') {
		url += '&filter_status=' + encodeURIComponent(filter_status); 
	}	
		
	var filter_date_added = $('input[name=\'filter_date_added\']').attr('value');
	
	if (filter_date_added) {
		url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
	}
	
	location = url;
}


$('input[name=\'filter_parent\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/customer/autocompleteCustomer&token=<?php echo $token; ?>&filter_customer=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.madn,
						value: item.customer_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'filter_parent\']').attr('value', ui.item.label);
	
		return false;
	},
	focus: function(event, ui) {
      return false;
   }
});
//--></script>
<script type="text/javascript"><!--
$(document).ready(function() {
	$('#date').datepicker({dateFormat: 'yy-mm-dd'});
});
//--></script>
<?php echo $footer; ?> 